package com.rui.service.impl;

import com.rui.domain.*;
import com.rui.mapper.InternshipLoggerMapper;
import com.rui.mapper.InternshipMapper;
import com.rui.mapper.MyCustomMapper;
import com.rui.service.InternshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("internshipService")
public class InternshipServiceImpl implements InternshipService {

    @Autowired
    private InternshipMapper internshipMapper;
    @Autowired
    private MyCustomMapper myCustomMapper;
    @Autowired
    private InternshipLoggerMapper internshipLoggerMapper;

    @Override
    public boolean insertInternship(Internship internship) {
        int row = internshipMapper.insert(internship);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<InternshipVO> findInternshipByStudentNumber(String stuNo) {
        List<InternshipVO> internshipList = myCustomMapper.findInternshipByStuNo(stuNo);
        if (internshipList != null && internshipList.size() > 0) {
            return internshipList;
        }
        return null;
    }

    @Override
    public boolean updateInternshipById(Internship internship) {
        int row = internshipMapper.updateByPrimaryKey(internship);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteInternshipById(String id) {
        int row = internshipMapper.deleteByPrimaryKey(id);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<InternshipVO> findInternshipByJobNo(String jobNo, int year) {
        StringIntDTO dto = new StringIntDTO(jobNo, year);
        return myCustomMapper.findInternshipByJobNo(dto);
    }

    @Override
    public List<InternshipLogger> findInternshipLogByJobNo(String jobNo, int year) {
        StringIntDTO dto = new StringIntDTO(jobNo, year);
        return myCustomMapper.findInternshipLogByJobNo(dto);
    }

    @Override
    public List<InternshipVO> findAll(String grade) {
        return myCustomMapper.findAllInternship(grade);
    }
}
